<%- unless @saved -%>
  TracksPages.page_error('<%=  t('todos.error_completing_todo', :description => @recurring_todo.description) %>');
<%- else
  object_name = unique_object_name_for("toggle_check_rec")
-%>
var <%=object_name%> = {
  animate: function() {
    TracksPages.set_page_badge(<%= @down_count %>);
    <%=object_name%>.remove_old_and_add_updated_recurring_todo();
    <%= "#{object_name}.inform_if_new_todo_created();" if @new_recurring_todo -%>
  },
  inform_if_new_todo_created: function() {
    TracksPages.page_inform('<%=  t('todos.new_related_todo_created') %>');
  },
  remove_old_and_add_updated_recurring_todo: function() {
    $('#<%=dom_id(@recurring_todo)%>').slideUp(1000, function() {
      $('#<%=dom_id(@recurring_todo)%>').remove();
      <%=object_name%>.show_empty_messages();

      <%- if @recurring_todo.completed? -%>
        <%=object_name%>.add_recurring_todo_to_completed_container();
      <%- else -%>
        <%=object_name%>.add_recurring_todo_to_active_container();
      <%- end -%>
    });
  },
  add_recurring_todo_to_completed_container: function() {
    $('#completed_recurring_todos_container').append(<%=object_name%>.html_for_recurring_todo());
    $('#<%= dom_id(@recurring_todo)%>').effect('highlight', {}, 2000 );
    $('#completed-empty-nd').hide();
  },
  add_recurring_todo_to_active_container: function() {
    $('#recurring_todos_container').append(<%=object_name%>.html_for_recurring_todo());
    $('#<%= dom_id(@recurring_todo)%>').effect('highlight', {}, 2000 );
    $('#recurring-todos-empty-nd').hide();
  },
  show_empty_messages: function() {
    <%- if @active_remaining == 0 -%>
      $('#recurring-todos-empty-nd').show();
    <%- end -%>
    <%- if @completed_remaining == 0 -%>
      $('#completed-empty-nd').show();
    <%- end -%>
  },
  html_for_recurring_todo: function() {
    return "<%= @saved ? js_render(@recurring_todo) : "" %>";
  }
}

<%=object_name%>.animate();
<%- end -%>
